<?
if($_POST)
{
	if($_FILES["photo"]["name"] != "")
	{
	$newname = explode(".",$_FILES['photo']['name']);
	$newname = "bgheader.".$newname[(sizeof($newname)-1)];
	@unlink("../imgs/".$_POST['oldpic']);
	@copy($_FILES["photo"]["tmp_name"],"../imgs/".strtolower($newname));
	($_POST['function'] == 1)? $fnc = "_repeat" : $fnc = "";
	$v['tables'] = "";
	$v['img_function'] = "bgheader".$fnc;
	$v['img_name1'] = $_POST['img_name1'];
	$v['img_link'] = $_POST['img_link'];
	$v['img_pic'] = strtolower($newname);
	$v['img_ip'] = $_SERVER['REMOTE_ADDR'];
	$chk = Q2("select * from images where img_function like '%bgheader%' ");
	if(count($chk) < 1){
		Qinsert("images","",$v);
	}else{
		Qupdate("images","",$v," img_function like '%bgheader%' ");
	}
	sleep(3);
	exit("<script type=\"text/javascript\">window.location='home.php?body=bgheader';</script>");
	}
}
?>

<p>

<img src="<?=bgheader()?>"  >
</p>

<p>
<fieldset>
<legend>Edit my  background header</legend>
<form action="" method="post" enctype="multipart/form-data" name="form1">
<label>Image file</label><input name="photo" type="file" />
<label>Image link</label><input name="img_link" type="text" value = "<?=$lfls['img_link']?>" /><span  style = "color:green;">Ex : http://www.youtube.com</span>
<label>Image Color</label><input name="img_name1" type="text" />
<label>Image Repeat</label><input name="function" type="checkbox" value="0" />
<br /><br />
<input name="" type="submit" value="<?=btsubmit()?>" /> <span style="color:#0C6">*รูปภาพควรมีความสูงที่ 105px</span>
<INPUT TYPE="hidden" name="oldpic" value="<?=bgheader()?>">
</form>
</fieldset>
</p>
<script type="text/javascript">
	$(document).ready(function(e) {
        
		$('input[name=function]').click(function(){
			var cnt = $('input[name=function]:checked').length;
			//alert(cnt);
			$('input[name=function]').val(cnt);
		});
    });
</script>